var m = Object.defineProperty;
var h = (i, t, e) =>
  t in i
    ? m(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e })
    : (i[t] = e);
var p = (i, t, e) => (h(i, typeof t != 'symbol' ? t + '' : t, e), e);
import {
  isMap as g,
  isPair as c,
  isScalar as d,
} from '../../nodes/identity.js';
import { Pair as a, createPair as v } from '../../nodes/Pair.js';
import { YAMLMap as w, findPair as n } from '../../nodes/YAMLMap.js';
import '../../visit.js';
import '../../stringify/stringifyString.js';
const o = class o extends w {
  constructor(t) {
    super(t), (this.tag = o.tag);
  }
  add(t) {
    let e;
    c(t)
      ? (e = t)
      : t &&
          typeof t == 'object' &&
          'key' in t &&
          'value' in t &&
          t.value === null
        ? (e = new a(t.key, null))
        : (e = new a(t, null)),
      n(this.items, e.key) || this.items.push(e);
  }
  /**
   * If `keepPair` is `true`, returns the Pair matching `key`.
   * Otherwise, returns the value of that Pair's key.
   */
  get(t, e) {
    const s = n(this.items, t);
    return !e && c(s) ? (d(s.key) ? s.key.value : s.key) : s;
  }
  set(t, e) {
    if (typeof e != 'boolean')
      throw new Error(
        `Expected boolean value for set(key, value) in a YAML set, not ${typeof e}`,
      );
    const s = n(this.items, t);
    s && !e
      ? this.items.splice(this.items.indexOf(s), 1)
      : !s && e && this.items.push(new a(t));
  }
  toJSON(t, e) {
    return super.toJSON(t, e, Set);
  }
  toString(t, e, s) {
    if (!t) return JSON.stringify(this);
    if (this.hasAllNullValues(!0))
      return super.toString(Object.assign({}, t, { allNullValues: !0 }), e, s);
    throw new Error('Set items must all have null values');
  }
  static from(t, e, s) {
    const { replacer: u } = s,
      f = new this(t);
    if (e && Symbol.iterator in Object(e))
      for (let l of e)
        typeof u == 'function' && (l = u.call(e, l, l)),
          f.items.push(v(l, null, s));
    return f;
  }
};
p(o, 'tag', 'tag:yaml.org,2002:set');
let r = o;
const P = {
  collection: 'map',
  identify: i => i instanceof Set,
  nodeClass: r,
  default: !1,
  tag: 'tag:yaml.org,2002:set',
  createNode: (i, t, e) => r.from(i, t, e),
  resolve(i, t) {
    if (g(i)) {
      if (i.hasAllNullValues(!0)) return Object.assign(new r(), i);
      t('Set items must all have null values');
    } else t('Expected a mapping for this tag');
    return i;
  },
};
export { r as YAMLSet, P as set };
